﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace MMK.Paket_Tracker.Runtime.Helper
{
    /// <summary>
    /// Collection of WPF helper tools
    /// </summary>
    public static class WPFTools
    {
        /// <summary>
        /// Finds the parent of a given object by name.
        /// </summary>
        /// <param name="searchItem">The item to explore.</param>
        /// <param name="name">The name to search for.</param>
        /// <returns>The searched FrameworkElement or null if an item with the given name doesn´t exist.</returns>
        public static FrameworkElement FindParentByName(FrameworkElement searchItem, String name)
        {
            FrameworkElement element = searchItem;

            while (element.Parent != null)
            {
                element = element.Parent as FrameworkElement;
                if (element.Name == name)
                {
                    return element;
                }
            }

            return null;
        }
    }
}
